﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace PDFWriter
{
   public static class Utility
    {
       static string xmlString;
       static XmlDocument xmlFile = new XmlDocument();

       public static string GetPDFString(string xmlString)
       {
           return GetPDFObject(xmlString).Text;
       }

        

      public static PDFObject GetPDFObject(string xmlString)
       {
           INode node = null;
           xmlFile.LoadXml(xmlString);
           string result = null;
           switch (xmlFile.FirstChild.Name)
           {
               case PDFDictionary.DICTIONARY:
                   {
                       node = new PDFDictionary(xmlString);
                       
                   }
                   break;           
               case PDFArray.ARRAY:
                   {
                       node = new PDFArray(xmlString);
                       
                   }
                   break;
               case PDFObjectReference.OBJ_REP:
                   {
                       node = new PDFObjectReference(xmlString);
                       
                   }
                   break;
               case PDFResource.RESOURCE_TAG:
                   {
                       node = new PDFResource(xmlString);
                       
                   }
                   break;
               case PDFPageContent.CONTENT_TAG:
                   {
                       node = new PDFPageContent(xmlString);

                   }
                   break; 
               case PDFStream.STREAM_TAG:
                   {
                       node = new PDFStream(xmlString);
                   }
                   break;

               case DocumentPage.PAGE:
                   {
                       string [] parameters = xmlString.Split(new char[DocumentPage.DELIMETER.ToCharArray()[0]]);
                       node = new DocumentPage(parameters[0],parameters[1]);
                   }
                   break; 
           }

           return node.GetPDFObject();           

       }
       public static List<PDFObject> GetPDFObjects(string xmlString)
       {
           INode node = null;
           xmlFile.LoadXml(xmlString.Split(DocumentPage.DELIMETER.ToCharArray()[0])[0]);
           string result = null;
           switch (xmlFile.FirstChild.Name)
           {
               case PDFDictionary.DICTIONARY:
                   {
                       node = new PDFDictionary(xmlString);
                       
                   }
                   break;           
               case PDFArray.ARRAY:
                   {
                       node = new PDFArray(xmlString);
                       
                   }
                   break;
               case PDFObjectReference.OBJ_REP:
                   {
                       node = new PDFObjectReference(xmlString);
                       
                   }
                   break;
               case PDFResource.RESOURCE_TAG:
                   {
                       node = new PDFResource(xmlString);
                       
                   }
                   break;
               case PDFPageContent.CONTENT_TAG:
                   {
                       node = new PDFPageContent(xmlString);

                   }
                   break; 
               case PDFStream.STREAM_TAG:
                   {
                       node = new PDFStream(xmlString);
                   }
                   break;

               case DocumentPage.PAGE:
                   {
                       string [] parameters = xmlString.Split(DocumentPage.DELIMETER.ToCharArray()[0]);
                       node = new DocumentPage(parameters[0],parameters[1]);
                   }
                   break; 
               case PDFFont.FONT:
                   {
                       node = new PDFFont(xmlString);
                   }
                   break;
               case DocumentRoot.DOCUMENT_ROOT:
                   {
                       node = new DocumentRoot(xmlString);
                   }
                   break;
               case PDFCatalog.CATALOG_TAG:
                   {
                       node = new PDFCatalog(xmlString);
                   }
                   break;
           }

           return node.GetPDFObjects();           

       }
    }
    }

